#include "WindowsInput.h"

#include <windows.h>

void WindowsInput::update()
{
	
	//Get new key states and save the old ones
    for (int k=0;k<256;++k){
		oldkeys[k] = keys[k];
		keys[k] = (GetAsyncKeyState(k) & 0x8000);
	}

	//Get the mouse location
	POINT pos;
	if (GetCursorPos(&pos) != 0) { 
	    
	    //Store the old position of the mouse
	    m_vMouseOldPos = m_vMousePos;
	    
	    //Save the new mouse position
		m_vMousePos = Vector(pos.x, pos.y);
	    
	    //Find the vector of movement
	    m_vMouseVector = m_vMousePos - m_vMouseOldPos;
	    
	    //Get the distance moved
	    m_fMouseDistance = m_vMouseVector.getLength();
	    
	    //If the mouse moved
	    if (m_fMouseDistance > 0)
			m_fMouseAngle = m_vMouseVector.getAngle(); 		//Store the mouse direction
		
	}
	else{
		
		std::cerr << "Windows Input error: Could not read mouse position information. Input values not updated." << std::endl;
		
		//Could not load the mouse position so return a rubbish value
		//mousepos = Vector3D(-1, -1, -1);
		
	}
	
}
